<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      姓:<span>
        <input type="text" v-model="firstName" />
      </span>
      名:<span>
        <input type="text" v-model="lastName" />
      </span>
      = <span>{{fullName}}</span> <br />
      <button @click="changeName">改名卡</button>
    </div>

    <script src="/js/vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          firstName: "刘",
          lastName: "备",
        },
        methods: {
          changeName() {
            this.fullName = this.firstName + this.lastName;
          },
        },
        // 默认配置只能获取 不能配置 
        computed: {
          // fullName(){
          //   return this.firstName +this.lastName;
          // }
          fullName: {
            get() {
              return this.firstName + this.lastName;
            },
            set(value) {
              this.firstName = value.slice(0, 1);
              this.lastName = value.slice(1);
              console.log(value);
            },
          },
        },
      });
    </script>
  </body>
</html>
